package com.biz.solr.entity;

import lombok.ToString;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;

/**
 * @ClasName IDoc
 * @Descripution TODO 所有文档继承此类 每个子实现类处理与其他Doc实体类业务字段关系
 * @Author USER
 * @Date 2022/3/25 11:51
 * @Version V1.0
 */
@ToString
public abstract class IDoc {



    private HashMap<String,String> RelevanceField;

    public static final String BIZFILEDSPILT = "#~~#";


    public static Object getConfigInstance(Class aClass){
        try {
            Object newInstance =  aClass.newInstance();
            return newInstance;
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

    public abstract void afterAddBizTypeRelevanceField();


    public void setRelevanceField(String role_arg_str){
        String[] role_arg = role_arg_str.split(BIZFILEDSPILT);
        if(role_arg.length != 2){
            return;
        }
        if(CollectionUtils.isEmpty(this.RelevanceField)){ //初始化数据
            HashMap<String, String> argMap = new HashMap<>();
            argMap.put(role_arg[0], role_arg[1]);
            this.RelevanceField = argMap;
        }else{
            HashMap<String, String> argMap = getRelevanceField();
            argMap.put(role_arg[0], role_arg[1]);
        }
    }

    public HashMap<String, String> getRelevanceField() {
        return RelevanceField;
    }

    public void setRelevanceField(HashMap<String, String> relevanceField) {
        RelevanceField = relevanceField;
    }
}
